//% color="#5bc2e8" iconWidth=50 iconHeight=40
namespace deepseek{
//% block="初始化deppseekAPI,apikey[api_key]" blockType="command"
//% api_key.shadow="normal" api_key.defl="XXXXX"
export function deepseek__init(parameter: any, block: any) {
let api_key=parameter.api_key.code
Generator.addImport(`from openai import OpenAI`)
Generator.addCode(`def deepseek_txt(txt):
    try:
    # 发送POST请求
        client = OpenAI(api_key=${api_key}, base_url="https://api.deepseek.com")
        response = client.chat.completions.create(
            model="deepseek-chat",
            messages=[
                {"role": "system", "content":txt},
                {"role": "user", "content":txt},
            ],
            stream=False
        )
        txt=response.choices[0].message.content
        return txt # 打印返回的报文内容   
    except Exception as e:
        return('Error occurred: ', str(e))
`)
}
//% block="输入消息:[TXT]" blockType="reporter"
//% TXT.shadow="normal" TXT.defl="您好！"
export function deepseek_content(parameter: any, block: any) {
let TXT=parameter.TXT.code     
Generator.addCode(`deepseek_txt(${TXT})`)
} 


}